<?php

namespace SinoPHP\BbdBoss\Api;

use InvalidArgumentException;
use Upfor\UpforPHP\Library\Math;

/**
 * 客户权限信息
 *
 * 用于API系统获取客户权限信息, 含域名列表
 *
 * Params:
 *      data:customerUserId     (integer)   客户ID
 */
class CustomerPrivilege extends ApiAbstract {

    public function v_1_0_0() {
        $params = $this->requestParams;

        if (empty($params['customerUserId']) || !Math::isInt($params['customerUserId'])) {
            throw new InvalidArgumentException('', 105001);
        }

        if (!model('CustomerUser')->getRow('*', ['customer_user_id' => $params['customerUserId'], 'status' => 1])) {
            throw new InvalidArgumentException('', 105002);
        }

        $domainList = model('CustomerDomain')->getList('domain_name', [
            'customer_user_id' => $params['customerUserId'],
            'is_delete' => 0,
            'domain_status' => 4,
        ]);

        $data = array(
            'domainList' => empty($domainList) ? array() : array_column($domainList, 'domain_name'),
        );

        // 成功, 返回success; 失败, 返回状态码+错误提示
        $this->success($data);
    }

}
